package com.itheima.my_reggie.config;

import com.itheima.my_reggie.common.JacksonObjectMapper;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.util.List;

@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
//      配置管理端的放行规则
        registry.addResourceHandler("/backend/**").addResourceLocations("classpath:/backend/");
//      配置客户端的放行规则
        registry.addResourceHandler("/front/**").addResourceLocations("classpath:/front/");
    }

//    设置数据的精准度配置，当前Id的值为long类型，在传递数据时会出现不精准的情况
    @Override
    protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
        MappingJackson2HttpMessageConverter messageConverter = new MappingJackson2HttpMessageConverter();
        JacksonObjectMapper mapper = new JacksonObjectMapper();
        messageConverter.setObjectMapper(mapper);
        converters.add(0,messageConverter);
    }

}
